package com.example.teststatisticesinterface.activity;

import android.app.Activity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.teststatisticesinterface.R;
import com.oppo.statistics.open.MobileClickAgent;

public class PageVisitActivity extends Activity implements OnClickListener{
	private Button btn_visiable;
	private boolean isVisible=false;
	private RelativeLayout layout;
	private TextView tv_matrix;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.pagevisit_activiy);
		initView();
	}

	private void initView() {
	
		
		btn_visiable=(Button)findViewById(R.id.btn_testVis);
		btn_visiable.setOnClickListener(this);
		
		tv_matrix=(TextView) findViewById(R.id.tv_matrix);
		tv_matrix.setText(showDisplayMetrics());
		
		layout=(RelativeLayout) findViewById(R.id.actionbar_test);
	}

	@Override
	protected void onPause() {
		MobileClickAgent.onPause(PageVisitActivity.this);
		super.onPause();
	}

	@Override
	protected void onResume() {
		MobileClickAgent.onResume(PageVisitActivity.this);
		super.onResume();
	}

	@Override
	public void onBackPressed() {
		super.onBackPressed();
		this.finish();
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_testVis:
			if (isVisible) {
				Animation animation=AnimationUtils.loadAnimation(PageVisitActivity.this, android.R.anim.fade_in);
				layout.startAnimation(animation);
				layout.setVisibility(View.VISIBLE);
			}else{
				Animation animation=AnimationUtils.loadAnimation(PageVisitActivity.this, android.R.anim.fade_out);
				layout.startAnimation(animation);
				layout.setVisibility(View.GONE);
			}
			isVisible=!isVisible;
			break;

		default:
			break;
		}
		
	}
	private String showDisplayMetrics(){
		
		DisplayMetrics dm=new DisplayMetrics();
		this.getWindowManager().getDefaultDisplay().getMetrics(dm);
		float decsity=dm.density;
		int decsityDpi=dm.densityDpi;
		int heightPixels=dm.heightPixels;
		int widthPixels=dm.widthPixels;
		float scaledDensity=dm.scaledDensity;
		float xdpi=dm.xdpi;
		float ydpi=dm.ydpi;
		
		StringBuilder sb=new StringBuilder();
		sb.append("decsity:").append(decsity).append("\n");
		sb.append("decsityDpi:").append(decsityDpi).append("\n");
		sb.append("heightPixels:").append(heightPixels).append("\n");
		sb.append("widthPixels:").append(widthPixels).append("\n");
		sb.append("scaledDensity:").append(scaledDensity).append("\n");
		sb.append("xdpi:").append(xdpi).append("\n");
		sb.append("ydpi:").append(ydpi).append("\n");
		Log.w("MainActivity", sb.toString());
		return sb.toString();
	}

}
